package cn.isgrow.gateway.controller;

import cn.isgrow.gateway.service.MongoDynamicRouteService;
import cn.isgrow.gateway.service.RedisDynamicRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @author Itachi is.xianglei@gmail.com
 * @Date 2020-05-22 23:31
 */
//@RestController
@RequestMapping("/gateway/redis/")
public class RedisDynamicRouteController {

    @Autowired
    private RedisDynamicRouteService redisDynamicRouteService;

    @PostMapping("/add")
    public String create(@RequestBody RouteDefinition entity) {
        String result = redisDynamicRouteService.add(entity);
        return String.valueOf(result);
    }

    @PostMapping("/update")
    public String update(@RequestBody RouteDefinition entity) {
        String result = redisDynamicRouteService.update(entity);
        return String.valueOf(result);
    }

    @DeleteMapping("/delete/{id}")
    public Mono<ResponseEntity<Object>> delete(@PathVariable String id) {
        return redisDynamicRouteService.delete(id);
    }

    @GetMapping("/")
    public Flux<RouteDefinition> findAll(){
        return redisDynamicRouteService.findAll();
    }

}
